<?php
	include 'head.php';
?>
<body>
<div id="header">
  <div id="toplink"> [<a href="../index.php" rel="_top" target="_top">回首页</a>] 
    <!--TODO:完成后台管理--> 
<!--
    [<a href="manageThread.php?mode=search">搜索</a>]   
    [<a href="manageThread.php?mode=status">系统信息</a>] 
    [<a href="manageThread.php?mode=admin">后台管理</a>] 
    [<a href="?">刷新</a>] 
-->    
    </div>
    
  <br>
  <h1>
    <?php
  	include '../common.php';
	$board_id = get_GETINT('board_id',0);
	echo $title[$board_id];//已经加入该字段了
	
  ?>
  </h1>
  <hr class="top">
</div>
<script type="text/javascript">
    window.onload=function(){
    var ds_textarea = document.getElementById("fcom");
    var faceList = ["|∀ﾟ", "(´ﾟДﾟ`)", "(;´Д`)", "(｀･ω･)", "(=ﾟωﾟ)=", "| ω・´)", "|-` )", "|д` )", "|ー` )", "|∀` )", "(つд⊂)", "(ﾟДﾟ≡ﾟДﾟ)", "(＾o＾)ﾉ", "(|||ﾟДﾟ)", "( ﾟ∀ﾟ)", "( ´∀`)", "(*´∀`)", "(*ﾟ∇ﾟ)", "(*ﾟーﾟ)", "(　ﾟ 3ﾟ)", "( ´ー`)", "( ・_ゝ・)", "( ´_ゝ`)", "(*´д`)", "(・ー・)", "(・∀・)", "(ゝ∀･)", "(〃∀〃)", "(*ﾟ∀ﾟ*)", "( ﾟ∀。)", "( `д´)", "(`ε´ )", "(`ヮ´ )", "σ`∀´)", " ﾟ∀ﾟ)σ", "ﾟ ∀ﾟ)ノ", "(╬ﾟдﾟ)", "(|||ﾟдﾟ)", "( ﾟдﾟ)", "Σ( ﾟдﾟ)", "( ;ﾟдﾟ)", "( ;´д`)", "(　д ) ﾟ ﾟ", "( ☉д⊙)", "(((　ﾟдﾟ)))", "( ` ・´)", "( ´д`)", "( -д-)", "(>д<)", "･ﾟ( ﾉд`ﾟ)", "( TдT)", "(￣∇￣)", "(￣3￣)", "(￣ｰ￣)", "(￣ . ￣)", "(￣皿￣)", "(￣艸￣)", "(￣︿￣)", "(￣︶￣)", "ヾ(´ωﾟ｀)", "(*´ω`*)", "(・ω・)", "( ´・ω)", "(｀・ω)", "(´・ω・`)", "(`・ω・´)", "( `_っ´)", "( `ー´)", "( ´_っ`)", "( ´ρ`)", "( ﾟωﾟ)", "(oﾟωﾟo)", "(　^ω^)", "(｡◕∀◕｡)", "/( ◕‿‿◕ )\\", "ヾ(´ε`ヾ)", "(ノﾟ∀ﾟ)ノ", "(σﾟдﾟ)σ", "(σﾟ∀ﾟ)σ", "|дﾟ )", "┃電柱┃", "ﾟ(つд`ﾟ)", "ﾟÅﾟ )　", "⊂彡☆))д`)", "⊂彡☆))д´)", "⊂彡☆))∀`)", "(´∀((☆ミつ"];
    var optionsList = document.getElementById("emotion").options;
    for (var i = 0; i < faceList.length; i++) {
        optionsList[1 + i] = new Option(faceList[i], faceList[i]);
    }
    document.getElementById("emotion").onchange = function (i) { 
        if (this.selectedIndex != 0) { 
            ds_textarea.value += this.value; 
            //alert(this.value);
            var l = ds_textarea.value.length; 
            ds_textarea.focus(); 
            ds_textarea.setSelectionRange(l, l); 
        } 
    }
    }
    <!-- TODO:return c():???? -->
    </script>
<form action="postThread.php" method="post" enctype="multipart/form-data" onsubmit="return c();" id="postform_main">
  <div id="postform">
  <!-- TODO:这块应该是有额外作用,权限,
  
    <input type="hidden" name="mode" value="regist">
    <input type="hidden" name="MAX_FILE_SIZE" value="2048000">
    <input type="hidden" name="upfile_path" value="">
    <input type="hidden" name="fid" value="1">
  -->
    
    <div style="text-align: center;">
      <table cellpadding="1" cellspacing="1" id="postform_tbl" style="margin: 0px auto; text-align: left;">
        <tbody>
          <tr>
            <td class="Form_bg"><b>名 称</b></td>
            <td><input type="text" name="name" id="fname" size="28" value="">
              <input type="submit" name="sendbtn" value="送 出"></td>
          </tr>
          <?php
		  	echo '<tr style="display:none"><td>';
			echo '<input type="text" name="board_id" value="'.$board_id.'">';
			echo '</td></tr>';
			
			include 'opDB.php';//在下面的处理中会关掉数据库
			$perPageThread = 5;//每页显示的串数
			$thread_pageNo = get_GETInt('thread_pageNo');
			

			$row = mysql_fetch_array(mysql_query('SELECT COUNT(*) AS `num_thread` FROM `thread` WHERE `boardId`='.$board_id ));
			$totalThreadNum = $row['num_thread'];
			//mysql_num_rows(mysql_query('SELECT `tId` FROM `thread` WHERE `boardId`='.$board_id));//TODO:得到Thread总数的方式可以优化
			if($totalThreadNum > 0)
				$totalThreadPage = floor(($totalThreadNum-1)/$perPageThread);
			else
				$totalThreadPage = 0;
			if($thread_pageNo > $totalThreadPage)$thread_pageNo = $totalThreadPage;
			echo '<tr style="display:none"><td>';
			echo '<input type="text" name="thread_pageNo" value="'.($thread_pageNo).'">';
			echo '</td></tr>';
		?>
          <tr style="display:none">
            <td class="Form_bg"><b>E-mail</b></td>
            <td><input type="text" name="email" value=""></td>
          </tr>
          <tr style="display:none">
            <td class="Form_bg"><b>标 题</b></td>
            <td><input type="text" name="title" id="fsub" size="28" value=""></td>
          </tr>
          <tr>
            <td class="Form_bg"><b>颜文字</b></td>
            <td><select id="emotion">
                <option value="" selected="selected">颜文字</option>
              </select></td>
          </tr>
          <tr>
            <td class="Form_bg"><b>内 文</b></td>
            <td><textarea name="content" id="fcom" cols="48" rows="4" style="width: 400px; height: 80px;"></textarea></td>
          </tr>
          <tr>
            <td class="Form_bg"><b>附加图片</b></td>
            <td><input type="file" name="upfile" id="fupfile" size="25"></td>
          </tr>
          <tr style="display:none">
            <td class="Form_bg"><b>类别</b></td>
            <td><input type="text" name="category" size="28" value="">
              <small>(请以 , 逗号分隔多个标籤)</small></td>
          </tr>
          <tr style="display:none">
            <td class="Form_bg"><b>删除用密码</b></td>
            <td><input type="password" name="pwd" size="8" maxlength="8" value="">
              <small>(删除文章用。英数字8字元以内)</small></td>
          </tr>
          <tr>
            <td colspan="2"><div id="postinfo">
                <ul>
                  <li>可附加图档类型：GIF, JPG, PNG, BMP，浏览器才能正常附加图档</li>
                  <li>附加图档最大上传资料量为 2000 KB。</li>
                  <li>当档桉超过宽 250 像素、高 250 像素时会自动缩小尺寸显示</li>
                </ul>
                <noscript>
                &lt;div&gt;＊您选择关闭了JavaScript，但这对您的浏览及发文应无巨大影响&lt;/div&gt;
                </noscript>
              </div></td>
          </tr>
        </tbody>
      </table>
    </div>
<!--    <script type="text/javascript">l1();</script> -->
    <hr>
  </div>
</form>

<div id="contents">

  <form action="manageThread.php" method="post">
    <div id="threads" class="autopagerize_page_element">
      <?php

		
		//改成按照最新回帖的顺序来排序
		
		$st_threadnum = $thread_pageNo*$perPageThread;
		
		$thread_sql = 'SELECT * FROM `thread` WHERE `boardId`="'.$board_id.'" ORDER BY `updateTime` DESC LIMIT '.$st_threadnum.', '.$perPageThread;//目前一页显示5个串
		$result = mysql_query($thread_sql);

		while($row = mysql_fetch_array($result)){
			//show thread	
			//这里字符串转换在post时转换即可,此处不用
			$tid = filter_var($row['tId'],FILTER_VALIDATE_INT)?intval($row['tId']):0;
			$userid = ($row['userId']);
			$content = ($row['content']);
			$posttime = ($row['postTime']); 
			
			$replynum_res_row = mysql_fetch_array(mysql_query('SELECT COUNT(*) AS `NUM_REPLY` FROM `reply` WHERE `tid`='.$tid));//使用COUNT计算数据条数
			$replynum = ($replynum_res_row['NUM_REPLY']);
			$title = ($row['title']);
			$postname = ($row['postName']);
			$picaddr = ($row['picAddr']);
			echo '<div class="threadpost" id='.$tid.' > <span class="comments" style="display:none">'.$replynum.'</span>';
			
			//显示图片
			if($picaddr != NULL){
				echo '<a href="'.$picaddr.'" rel="_blank" target="_blank"> 
				<img src="'.$picaddr.'" class="img" style="max-width:250px; max-height:250px"> </a>';	
			}
			
			echo '</span>  <input type="checkbox" name='.$tid.' value="deleteT">
        			<span class="title" style="display:none">'.$title.' </span>
					 名称: <span class="name"> '.$postname.' </span>
			        ['.substr($posttime,0,strpos($posttime,' ')).'('.week($posttime).')'.substr($posttime,strpos($posttime,' ')+1);


			echo ' ID:'.$userid.']
			        <a href="showThread.php?tid='.$tid.'&board_id='.$board_id.'" class="qlink"> No.'.$tid.'</a>&nbsp;
					[<a href="showThread.php?tid='.$tid.'&board_id='.$board_id.'" >回应</a>]
			        <div class="quote">
		          '.$content.'</div><br>';//显示一下星期几
			if($replynum>10){
				echo '<span class="warn_txt2">有 '.($replynum-10).' 篇回应被省略。要查看所有回应請按下回应连接。</span> </div>';
			}
			echo'</div>';
	  		
			
			//show reply
			$reply_sql = 'SELECT * FROM `reply` WHERE tId='.$tid.' ORDER BY `postTime` LIMIT '.(($replynum-10)>0?$replynum-10:0).', 10 ';//最多取10条消息
			$result_reply = mysql_query($reply_sql);
			while($row_reply=mysql_fetch_array($result_reply)){	
				$r_posttime = $row_reply['postTime'];
				$r_picaddr = $row_reply['picAddr'];
	  			echo '<div class="reply" id="'.$row_reply['rId'].'">
        <div class="replywrap">';
				if($r_picaddr != NULL){
					echo '<a href="'.$r_picaddr.'" rel="_blank" target="_blank"> 
					<img src="'.$r_picaddr.'" class="img" style="max-width:250px; max-height:250px"> </a>';	
				}
				echo' <input type="checkbox" name="'.$row_reply['rId'].'" value="deleteR">
          <span class="title" style="display:none">'.$row_reply['title'].'</span> 名称: <span class="name">'.$row_reply['postName'].'</span> 
		  ['.substr($r_posttime,0,strpos($r_posttime,' ')).'('.week($r_posttime).')'.substr($r_posttime,strpos($r_posttime,' ')+1).' ID:'.$row_reply['rId'].'] <a href="showThread.php?tid='.$tid.'" class="qlink">No.'.$row_reply['rId'].'</a> &nbsp;
          <div class="quote">'.$row_reply['content'].'</div>
        </div>
      </div>';//TODO:此处默认链接翻到最后一页
	  
	  
	  
			}
			echo "<hr>";
		}
		mysql_close($con);
	?>
     <!-- 
      <div class="threadpost" id="r309828"> <span class="comments" style="display:none">1</span> <a href="/Public/Upload/2015-03-25/551269761d8c2.jpg" rel="_blank" target="_blank"> <img src="/Public/Upload/2015-03-25/551269761d8c2_t.jpg" class="img" style="max-width:250px; max-height:250px"> </a>
        <input type="checkbox" name="309828" value="delete">
        <span class="title" style="display:none">无标题</span> 名称: <span class="name">爆炸吧现充</span> [2015-03-25(三)15:53:26 ID:Yow7vap] <a href="/home/forum/thread/id/309828.html#309828" class="qlink">No.309828</a>&nbsp;[<a href="/home/forum/thread/id/309828.html">回应</a>]
        <div class="quote">(´ﾟДﾟ`)</div>
        <br>
      </div>
      <div class="reply" id="r309846">
        <div class="replywrap">
          <input type="checkbox" name="309846" value="delete">
          <span class="title" style="display:none">无标题</span> 名称: <span class="name">无名氏</span> [2015-03-25(三)15:59:59 ID:PaVVh7f] <a href="/home/forum/thread/id/309828.html#309846" class="qlink">No.309846</a> &nbsp;
          <div class="quote">(＾o＾)ﾉ 肥宅要是壁咚的话会把脆弱的墙弄塌吧！</div>
        </div>
      </div>
      <hr>
      -->
    </div>
    <div id="del">
      <table style="float: right;">
        <tbody>
          <tr>
            <td align="center" style="white-space: nowrap;">
              <?php echo'<input type="hidden" name="ref" value="news.php?board_id='.$board_id.'&thread_pageNo='.$thread_pageNo.'">';?>
              <input type="hidden" name="mode" value="usrdel">
              【刪除文章】[
              <input type="checkbox" name="onlyimgdel" id="onlyimgdel" value="on">
              <label for="onlyimgdel">仅删除附加图片</label>
              ]<br>
              删除用密码:
              <input type="password" name="pwd" size="8" value="">
              <input type="submit" value=" 执行 "></td>
          </tr>
        </tbody>
      </table>
    </div>
<!--    <script type="text/javascript">l2();</script>-->
    <div id="page_switch">
    <div>
    <?php 
	  	//echo '<p>'.$thread_pageNo.'</p>'; //test
	  	if($thread_pageNo>0){
			echo '<a class="prev" style="white-space: nowrap;" href="news.php?thread_pageNo='.($thread_pageNo-1).'&board_id='.$board_id.'">上一页</a> ';	
		}
		if($thread_pageNo>5){
			echo '[<a class="num" href="news.php?thread_pageNo='.(0).'&board_id='.$board_id.'">1</a>]  ... ';	
		}	
		$i=($thread_pageNo-5)>0?$thread_pageNo-5:0;
		for(;$i<=$thread_pageNo-1;++$i){
			echo '[<a class="num" href="news.php?thread_pageNo='.$i.'&board_id='.$board_id.'">'.($i+1).'</a>] ';	
		}
		echo '<span class="current">['.($thread_pageNo+1).'] </span>';
		
		
		for($i=$thread_pageNo+1;$i<=$totalThreadPage;++$i){
			echo '[<a class="num" href="news.php?thread_pageNo='.$i.'&board_id='.$board_id.'">'.($i+1).'</a>] ';	
		}
		if($thread_pageNo+5 < $totalThreadPage){
			echo ' ... [<a class="end" href="news.php?thread_pageNo='.$totalThreadPage.'&board_id='.$board_id.'">'.($totalThreadPage+1).'</a>] ';	
		}
		if($thread_pageNo != $totalThreadPage){
			echo '<a class="next" style="white-space: nowrap;" href="news.php?thread_pageNo='.($thread_pageNo+1).'&board_id='.$board_id.'">下一页</a>';
		}
		
	  ?>
      </div>
    </div>
    <div id="footer"> 
     <!-- <script type="text/javascript" src="http://tajs.qq.com/stats?sId=35757723" charset="UTF-8"></script>
      <div id="tc-iqsi5f1w"><a href="http://www.trendcounter.com/report/iqsi5f1w/" target="_blank"><img src="http://www.trendcounter.com/w/blog/iqsi5f1w.png?v=3&amp;l=zh&amp;w=1366&amp;h=768&amp;r=&amp;k=1&amp;c=1&amp;p=http%3A%2F%2Fh.adnmb.com%2Fhome%2Fforum%2Fshowt%2Fid%2F1.html&amp;t=-%20Acfun%E5%8C%BF%E5%90%8D%E7%89%88&amp;z=1131626222" border="0" alt="trendcounter" title="Click here to see more stats!"></a></div>
      <script type="text/javascript">
var _tcq = _tcq || []; _tcq.push(['widget', 'blog']); _tcq.push(['init', 'iqsi5f1w']); 
(function(d, s) { var e = d.createElement(s); e.type = 'text/javascript';
e.async = true; e.src = 'http://s.tcimg.com/w/v3/trendcounter.js';
var f = d.getElementsByTagName(s)[0]; f.parentNode.insertBefore(e, f); })(document, 'script');
</script>

      <script type="text/javascript">preset();</script> 
      	--> 
    </div>
    <!--    统计信息    --> 
    <!--    cpu 0.2204s ( Load:0.0004s Init:0.0006s Exec:0.2134s Template:0.0060s )    --> 
    <!--    memory 1,369.63 kb    --> 
    <!--    sql 263 queries 163 writes     --> 
    <!--    cache 332 gets 40 writes     -->
    
  </form>
</div>
</body>
</html>